package com.juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author: tzj
 * @create: 2021-07-05
 **/
public class AQSDemo {
    static Lock lock = new ReentrantLock(true);

    public static void main(String[] args) {
        new Thread(() -> {
            lock.lock();
            try {
                System.out.println("A客户办理业务。。。。。。");
                TimeUnit.MINUTES.sleep(40);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }, "A").start();

        new Thread(() -> {
            lock.lock();
            try {
                System.out.println("B客户办理业务。。。。。。");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }, "B").start();

        new Thread(() -> {
            lock.lock();
            try {
                System.out.println("C客户办理业务。。。。。。");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }, "C").start();
    }
}
